require 'ldap'
class Auth < ActiveRecord::Base
  def self.auth_ldap(username, password)
    uid = BluePages.get_uid(username)
    if uid.nil? # couldn't find user data
      return false
    end
    c = username.split(/[.@]/)[1]      # gets xx out of name@xx.ibm.com
    begin
      ldap = LDAP::Conn.new('bluepages.ibm.com', 389)
      ldap.bind("uid=#{uid},c=#{c},ou=bluepages,o=ibm.com", password)
    rescue LDAP::ResultError
      return false
    end
    ldap.unbind()
    return true
  end
end
